package com.threeidiots.transport.entities;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "REQUESTS")
public class Request {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "REQ_ID")
	private Long requestId;

	@Temporal(TemporalType.DATE)
	@Column(name = "REQ_DATE", nullable = false)
	private Date requestedDate;

	@Temporal(TemporalType.TIME)
	@Column(name = "REQ_TIME", nullable = false)
	private Date requestedTime;

	@Column(name = "REQ_TYPE", nullable = false, length = 10)
	private String requestType;

	@Temporal(TemporalType.DATE)
	@Column(name = "CREATED", nullable = false)
	private Date creationDate;

	@Column(name = "OFFICE_LOC", nullable = false, length = 25)
	private String officeLocation;

	@OneToOne(targetEntity = com.threeidiots.transport.entities.RequestStatus.class)
	private RequestStatus lastRequestStatus;

	@OneToOne(targetEntity = com.threeidiots.transport.entities.Employee.class)
	private Employee requestor;

	@OneToOne(targetEntity = com.threeidiots.transport.entities.Employee.class)
	private Employee approver;

	@OneToMany
	@JoinColumn(name = "REQ_ID")
	private Set<RequestDetails> requestDetails;

	/**
	 * @return the requestId
	 */
	public Long getRequestId() {
		return requestId;
	}

	/**
	 * @param requestId
	 *            the requestId to set
	 */
	public void setRequestId(Long requestId) {
		this.requestId = requestId;
	}

	/**
	 * @return the requestedDate
	 */
	public Date getRequestedDate() {
		return requestedDate;
	}

	/**
	 * @param requestedDate
	 *            the requestedDate to set
	 */
	public void setRequestedDate(Date requestedDate) {
		this.requestedDate = requestedDate;
	}

	/**
	 * @return the requestedTime
	 */
	public Date getRequestedTime() {
		return requestedTime;
	}

	/**
	 * @param requestedTime
	 *            the requestedTime to set
	 */
	public void setRequestedTime(Date requestedTime) {
		this.requestedTime = requestedTime;
	}

	/**
	 * @return the requestType
	 */
	public String getRequestType() {
		return requestType;
	}

	/**
	 * @param requestType
	 *            the requestType to set
	 */
	public void setRequestType(String requestType) {
		this.requestType = requestType;
	}

	/**
	 * @return the creationDate
	 */
	public Date getCreationDate() {
		return creationDate;
	}

	/**
	 * @param creationDate
	 *            the creationDate to set
	 */
	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	/**
	 * @return the officeLocation
	 */
	public String getOfficeLocation() {
		return officeLocation;
	}

	/**
	 * @param officeLocation
	 *            the officeLocation to set
	 */
	public void setOfficeLocation(String officeLocation) {
		this.officeLocation = officeLocation;
	}

	/**
	 * @return the lastRequestStatus
	 */
	public RequestStatus getLastRequestStatus() {
		return lastRequestStatus;
	}

	/**
	 * @param lastRequestStatus
	 *            the lastRequestStatus to set
	 */
	public void setLastRequestStatus(RequestStatus lastRequestStatus) {
		this.lastRequestStatus = lastRequestStatus;
	}

	/**
	 * @return the requestor
	 */
	public Employee getRequestor() {
		return requestor;
	}

	/**
	 * @param requestor
	 *            the requestor to set
	 */
	public void setRequestor(Employee requestor) {
		this.requestor = requestor;
	}

	/**
	 * @return the approver
	 */
	public Employee getApprover() {
		return approver;
	}

	/**
	 * @param approver
	 *            the approver to set
	 */
	public void setApprover(Employee approver) {
		this.approver = approver;
	}

	/**
	 * @return the requestDetails
	 */
	public Set<RequestDetails> getRequestDetails() {
		return requestDetails;
	}

	/**
	 * @param requestDetails
	 *            the requestDetails to set
	 */
	public void setRequestDetails(Set<RequestDetails> requestDetails) {
		this.requestDetails = requestDetails;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((requestId == null) ? 0 : requestId.hashCode());
		result = prime * result
				+ ((requestor == null) ? 0 : requestor.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Request))
			return false;
		Request other = (Request) obj;
		if (requestId == null) {
			if (other.requestId != null)
				return false;
		} else if (!requestId.equals(other.requestId))
			return false;
		if (requestor == null) {
			if (other.requestor != null)
				return false;
		} else if (!requestor.equals(other.requestor))
			return false;
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Request [approver=" + approver + ", requestId=" + requestId
				+ ", requestType=" + requestType + ", requestedDate="
				+ requestedDate + ", requestor=" + requestor + "]";
	}

}
